<?php

use Faker\Factory as Faker;
use App\Models\House;
use App\Repositories\HouseRepository;

trait MakeHouseTrait
{
    /**
     * Create fake instance of House and save it in database
     *
     * @param array $houseFields
     * @return House
     */
    public function makeHouse($houseFields = [])
    {
        /** @var HouseRepository $houseRepo */
        $houseRepo = App::make(HouseRepository::class);
        $theme = $this->fakeHouseData($houseFields);
        return $houseRepo->create($theme);
    }

    /**
     * Get fake instance of House
     *
     * @param array $houseFields
     * @return House
     */
    public function fakeHouse($houseFields = [])
    {
        return new House($this->fakeHouseData($houseFields));
    }

    /**
     * Get fake data of House
     *
     * @param array $postFields
     * @return array
     */
    public function fakeHouseData($houseFields = [])
    {
        $fake = Faker::create();

        return array_merge([
            'title' => $fake->word,
            'cover' => $fake->word,
            'content' => $fake->word,
            'item_id' => $fake->randomDigitNotNull,
            'channel_id' => $fake->randomDigitNotNull,
            'read_num' => $fake->randomDigitNotNull,
            'country' => $fake->word,
            'state_id' => $fake->randomDigitNotNull,
            'state' => $fake->word,
            'state_name' => $fake->word,
            'county_id' => $fake->randomDigitNotNull,
            'county' => $fake->word,
            'county_name' => $fake->word,
            'zip_id' => $fake->randomDigitNotNull,
            'zip_code' => $fake->word,
            'zip' => $fake->word,
            'zip_name' => $fake->word,
            'address' => $fake->word,
            'status' => $fake->randomDigitNotNull,
            'updated_at' => $fake->word,
            'created_at' => $fake->word
        ], $houseFields);
    }
}
